package com.ruoyi.graph.dao;

import com.ruoyi.graph.domain.TableNode;
import com.ruoyi.graph.domain.Relationship;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;

import java.util.List;

public interface TableDao extends Neo4jRepository<TableNode,Long> {

    @Query("match(n:TableNode {database:{0},tableName:{1}}) return n")
    TableNode findByName(String database, String tableName);

    @Query("MATCH (n:TableNode) -[t:RELATIONSHIP]->(m:TableNode) return n,t,m")
    List<Relationship> getAllNodes();

    @Query("match (a)<-[r*0..]-(b) where a.tableName={0} and a.database={1} return b" +
            " union all " +
            "match (a)-[r*..]->(b) where a.tableName={0} and a.database={1} return b")
    List<TableNode> findAllUpAndDownStream(String tableName, String database);


}
